import { fetchData,postData,delData, putData } from '../../api/index';

export default function(){
    let sam_url = "/api/sample";
    let sam_add_url = "/api/sample/add"
    let getSample = async () => {
        try {
            const res = await fetchData(sam_url);
            return res
        } catch (error) {
        }
    }
    let postSample = <T>(data:T) => {
        try {
            const res = postData(sam_url,data);
            return res
        } catch (error) {

        }
    }
    let postSampleAction = <T>(data:T,action:string) => {
        try {
            const res = postData(sam_url + "/" + action,data)
            return res
        } catch (error) {

        }
    }
    let postSampleAdd = async <T>(data:T) => {
        try {
            const res = await postData(sam_add_url,data)
            return res
        } catch (error) {

        }
    }
    let querySample = async <T>(query:T) => {
        try{
            const res = await postData(sam_url,query);
            return res
        } catch (error) {

        }
    }
    let delSample = async (id:number) => {
        try{
            let sam_del_url = sam_url;
            const res = delData(sam_del_url + '/' + id);
            return res
        } catch (error) {

        }
    }
    let editSample = async <T>(id:number,data:T) => {
        try {
            const res = await putData(sam_url + '/' + id,data);
            return res
        } catch (error) {
            
        }
    }
    return { getSample,postSample,postSampleAdd,delSample,querySample,postSampleAction,editSample,sam_url }
}